﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DbContext;
using SmartPlant.Model.Biz;
using SmartPlant.Model.DbContext;
using SmartPlant.Services.Interfaces;
using SmartPlant.WinCore;
namespace SmartPlant.Services
{
    public class RevisionService : BaseService, IRevisionService
    {

        public async Task<List<Revision>> GetById(decimal dwgid)
        {
            string url = $"/api/Project/{GlobalObject.CurrentProject.ProjId}/revision-api/by-dwg-id/{dwgid}";
            var res = await GetAsync<List<Revision>>(url);
            return res.data;
        }
        public async Task<bool> UpdateRevisionAsync(decimal proId, Revision dwgid)
        {
            string uri = $"/api/Project/{proId}/revision-api";
            var r = await PutBodyAsync<bool, Revision>(uri, dwgid);
            return r.data;
        }
        //public async Task<bool> DeleteRevisionAsync(decimal proId, Revision dwgid, decimal revid)
        //{
        //    string uri = $"/api/Project/{proId}/revision-api/{dwgid}/{revid}";
        //    var r = await PutBodyAsync<bool, Revision>(uri, dwgid);
        //    return r.data;
        //}

        public async Task<bool> DeleteRevisionAsync(decimal proId, decimal dwgid, decimal revid)
        {
            string uri = $"/api/Project/{proId}/revision-api/{dwgid}/{revid}";
            var r = await DeleteAsync<bool> (uri);
            return r.data;
        }

        public async Task<Revision> GetId(string dwgid)
        {
            string url = $"/api/Project/{GlobalObject.CurrentProject.ProjId}/revision-api/by-dwg-id/{dwgid}";
            var res = await GetAsync<Revision>(url);
            return res.data;
        }

        public async Task<Revision> InsertRevisionAsync(decimal proId,Revision revision)
        {
            string uri = $"/api/Project/{proId}/revision-api/insert_-revision";
            var r = await PostBodyAsync<Revision, Revision>(uri, revision);
            return r.data;
        }
    }
}
